<template>
  <div class="right-nav" :style="style" v-show="init">
    <ul :class="{ close: !ulOpen }">
      <li @click="ulOpen = true"></li>
      <li>
        <router-link :to="{ name: 'Application' }">应用系统</router-link>
      </li>
      <li>
        <router-link :to="{ name: 'Flow' }">我的待办</router-link>
      </li>
      <li>
        <router-link :to="{}">我的消息</router-link>
      </li>
      <li>
        <router-link :to="{}">资源列表</router-link>
      </li>
      <li class="close-btn" @click="ulOpen = false">收起</li>
    </ul>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";

@Component({
  name: "RightNav",
  components: {}
})
export default class RightNav extends Vue {
  private ulOpen = true;
  private style: any = {};
  private init = false;

  private mounted() {
    this.autoPosition();
  }

  /**
   * 自动计算头部高度和右边距样式
   */
  private autoPosition() {
    const bodyStart: HTMLElement | null = document.querySelector("#body-start");

    if (bodyStart) {
      const right = Math.floor((window.innerWidth - bodyStart.clientWidth) / 2);

      // this.$set(this.style, "right", `${right - 80 }px`);
      this.style = {
        right: `${right > 80 ? right - 80 : 10}px`,
        top: `${bodyStart.offsetTop}px`
      };
      this.init = true;
    }
  }
}
</script>

<style lang="less" scoped>
@import "~@/assets/style/mixin.less";
.right-nav {
  position: fixed;
  z-index: 10;
  ul {
    transition: height 0.3s ease-out;
    // transition-duration: 0.5s;
    height: 292px;
    background: white;
    overflow: hidden;

    &.close {
      // transition: max-height 0.3s ease-out;
      height: 47px;
      overflow: hidden;
    }
  }
  li {
    width: 47px;
    height: 47px;
    font-size: 12px;
    line-height: 120%;
    background-color: #273972;
    margin-top: 2px;
    cursor: pointer;
    letter-spacing: 1px;
    text-align: center;
    color: white;

    a {
      padding: 10px;
      color: white;
      display: block;
    }

    &:first-child,
    &:last-child {
      padding: 10px;
    }

    &:first-child {
      margin-top: 0;
      background: url("./images/bg-1.png") center center no-repeat;
      background-size: 100%;
    }
  }

  .close-btn {
    &::before {
      content: "";
      border-top: 2px solid white;
      border-left: 2px solid white;
      width: 10px;
      height: 10px;
      display: block;
      transform: rotate(45deg);
      margin: 2px auto;
    }
  }
}
</style>
